/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       animated_window.h

	$Header: /game/animated_window.h $

	$NoKeywords: $

 ************************************************************************/
#ifndef ANIMATED_WINDOW_H_INCLUDED
#define ANIMATED_WINDOW_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <vector>
#include "animation_ptr.h"
#include "bitmap_group_window.h"
#include "idle_processor.h"
#include "sized_int_types.h"
#include "window_handler.h"

// note: a "speed" of 100 uses the normal rate of animation, as specified in the resource.
// higher or lower numbers yield faster or slower animations.

class t_animated_window : public t_bitmap_group_window, public t_idle_processor
{
public:
	t_animated_window( t_animation_ptr const& bitmaps, t_screen_point point, int speed = 100,
		               t_window* parent = 0 );
	void			 enable_animation( bool arg = true );
	int				 get_frame() const;
	int				 get_start_frame() const;
	int				 get_end_frame() const;
	t_window_handler get_end_handler() const;
	void			 set_frame( int frame );
	void			 set_range( int start, int stop, bool cycle = true );
	void			 set_end_handler( t_window_handler handler );

protected:
	virtual void on_animation_end();
	virtual void on_idle();

	bool             m_cycle; // true if animation should loop forever.
	int              m_start_frame;
	int              m_end_frame;
	t_window_handler m_end_handler;
	int              m_frame;
	std::vector<int> m_frame_order;
};

inline t_window_handler t_animated_window::get_end_handler() const
{
	return m_end_handler;
}

inline int t_animated_window::get_start_frame() const
{
	return m_start_frame;
}

inline int t_animated_window::get_end_frame() const
{
	return m_end_frame;
}

inline int t_animated_window::get_frame() const
{
	return m_frame;
}

inline void t_animated_window::enable_animation( bool arg )
{
	if (arg == is_active())
		return;
	if (arg)
		resume_idle_processing();
	else
		suspend_idle_processing();
}

inline void t_animated_window::set_frame( int frame )
{
	m_frame = frame;
	t_bitmap_group_window::set_frame( m_frame_order[frame] );
}

inline void t_animated_window::set_range( int start, int stop, bool cycle )
{
	m_start_frame = start;
	m_end_frame = stop;
	m_cycle = cycle;
}

inline void t_animated_window::set_end_handler( t_window_handler handler )
{
	m_end_handler = handler;
}

#endif // ANIMATED_WINDOW_H_INCLUDED